package com.tansun.easycare.rule.common.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.tansun.easycare.rule.common.JsonMessage;
import com.tansun.easycare.rule.common.RuleBaseController;
import com.tansun.easycare.rule.common.model.ResponseVO;
import com.tansun.easycare.rule.common.service.RuleGeneralService;
import com.tansun.easycare.rule.decisiontree.entity.DecisionTreeEntity;
import com.tansun.easycare.rule.decisiontree.service.DecisionTreeService;

@RestController
@RequestMapping(value = "/ruleproj/external")
public class RuleExternalController extends RuleBaseController {

	@Autowired
	private RuleGeneralService RuleGeneralService;
	@Autowired
	private DecisionTreeService decisionTreeService;

	/**
	 * 决策树规则生成发布生效接口
	 * @return
	 */
	@RequestMapping("generalRuleTree")
	public @ResponseBody JsonMessage generalRuleTree(DecisionTreeEntity treeEntity, String serverUrl) {
		JsonMessage ret = new JsonMessage();
		try {
			String result = RuleGeneralService.saveAndDeployRuleTree(treeEntity, serverUrl);
			ret.setData(result);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			ret.setResult(false);
			ret.setMessage(e.getMessage());
		}
		return ret;
	}

	/**
	 * 获取决策树模型信息接口
	 * 
	 * @param request
	 * @param decisionTreeId
	 * @param isedit
	 * @param version
	 * @param map
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("gettreedetail")
	public ResponseVO gettreedetail(String manageId) {
		ResponseVO ret = new ResponseVO();
		try {
			Object reMap = decisionTreeService.getTreeInfo(manageId, null, null,null);
			ret.setData( reMap);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			ret.setStatus(ResponseVO.ERROR);
			ret.setDescription(e.getMessage());
		}
		return ret;
	}
}
